package com.starview.star.compiler.macrocompile;

import java.util.HashMap;

import com.starview.star.compiler.ast.IAbstract;
import com.starview.star.compiler.util.Dict;

@SuppressWarnings("serial")
public class MacroDict extends Dict<MacroDescriptor>
{
  final IAbstract replaceVar;

  protected MacroDict(IAbstract replaceVar, MacroDict outer)
  {
    super(outer, new HashMap<String, MacroDescriptor>());
    this.replaceVar = replaceVar;
  }

  public MacroDict(IAbstract replaceVar)
  {
    this(replaceVar, null);
  }

  public IAbstract getReplaceVar()
  {
    return replaceVar;
  }

  public boolean isReplaceVar(IAbstract v)
  {
    if (v.equals(replaceVar))
      return true;
    else if (getOuter() != null)
      return ((MacroDict) getOuter()).isReplaceVar(v);
    else
      return false;
  }

  @Override
  public MacroDict fork()
  {
    return new MacroDict(replaceVar, this);
  }

  public MacroDict fork(IAbstract replaceVar)
  {
    return new MacroDict(replaceVar, this);
  }
}
